Skip to content

Implement Flask backend API with progress tracking endpoints - #80

Draft
moulongzhang with Copilot wants to merge 4 commits into
mainfrom
copilot/implement-backend-api-with-flask
Draft

Implement Flask backend API with progress tracking endpoints#80
moulongzhang with Copilot wants to merge 4 commits into
mainfrom
copilot/implement-backend-api-with-flask

Conversation

Copilot AI commented Dec 16, 2025

Copy link
Copy Markdown

Implements Step 3: Flask backend API with / and /api/progress routes for progress data management using hybrid in-memory/file storage.

Implementation

  • Flask App (main.py)

    • / - API endpoint documentation
    • /api/progress GET - Returns progress data array
    • /api/progress POST - Appends progress entry, persists to progress.json
    • Thread-safe operations via threading.Lock() for concurrent request handling
  • Tests (test_main.py)

    • 7 pytest cases: route validation, GET/POST operations, error handling, file persistence
    • Fixture-based test client setup with automatic cleanup
  • Dependencies

    • Flask 3.0.0, pytest 7.4.3

Example Usage

# POST /api/progress
{
  "task": "Implement API",
  "status": "completed",
  "percentage": 100
}

# Response 201
{
  "success": true,
  "message": "Progress saved successfully",
  "data": {...}
}

Security

  • Debug mode disabled to prevent arbitrary code execution via debugger
  • Input validation on POST requests returns 400 for missing data
Original prompt

This section details on the original issue you should resolve

<issue_title>ステップ3: バックエンドAPIの実装</issue_title>
<issue_description>## 概要
FlaskでバックエンドAPIを実装する

タスク

  • Flaskで/(トップページ)と/api/progress(進捗データGET/POST)ルートを作成
  • 進捗データをインメモリ or ファイル保存
  • APIの単体テスト(pytest等)

参照

plan.md のステップ3に基づく実装</issue_description>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Co-authored-by: moulongzhang <39043782+moulongzhang@users.noreply.github.com>
Comment thread main.py Fixed
Comment thread main.py Fixed
Copilot AI and others added 2 commits December 16, 2025 08:30
Co-authored-by: moulongzhang <39043782+moulongzhang@users.noreply.github.com>
Co-authored-by: moulongzhang <39043782+moulongzhang@users.noreply.github.com>
Comment thread main.py
Comment on lines +81 to +84
return jsonify({
"success": False,
"error": str(e)
}), 500

Check warning

Code scanning / CodeQL

Information exposure through an exception Medium

Stack trace information
flows to this location and may be exposed to an external user.

Copilot Autofix

AI 9 months ago

To fix the issue, we should avoid returning the actual exception message str(e) to the user in the JSON response. Instead, we should:

  • Return a generic error message such as "An internal error occurred!" or similar in the API response. This prevents leakage of exception details.
  • Optionally, to help with debugging, log the exception (including stack trace) on the server side using Python's logging module or print(traceback.format_exc()).
  • The change is to the except block in the post_progress route, i.e., lines 81–83 of file main.py.
  • Additionally, import the traceback module (if logging a stack trace was chosen) and/or the logging module.
  • If a logging solution is not already set up, use print(traceback.format_exc()) for simplicity.

Suggested changeset 1
main.py

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/main.py b/main.py
--- a/main.py
+++ b/main.py
@@ -2,7 +2,7 @@
 import json
 import os
 import threading
-
+import traceback
 app = Flask(__name__)
 
 # In-memory storage for progress data
@@ -78,9 +78,10 @@
             "data": data
         }), 201
     except Exception as e:
+        print(traceback.format_exc())
         return jsonify({
             "success": False,
-            "error": str(e)
+            "error": "An internal error has occurred."
         }), 500
 
 if __name__ == '__main__':
EOF
@@ -2,7 +2,7 @@
import json
import os
import threading

import traceback
app = Flask(__name__)

# In-memory storage for progress data
@@ -78,9 +78,10 @@
"data": data
}), 201
except Exception as e:
print(traceback.format_exc())
return jsonify({
"success": False,
"error": str(e)
"error": "An internal error has occurred."
}), 500

if __name__ == '__main__':
Copilot is powered by AI and may make mistakes. Always verify output.
Copilot AI changed the title [WIP] Implement backend API using Flask Implement Flask backend API with progress tracking endpoints Dec 16, 2025
Copilot AI requested a review from moulongzhang December 16, 2025 08:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ステップ3: バックエンドAPIの実装

3 participants